<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
header('Content-Type: charset=utf-8');
include '../../operations/connection.php';
$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;
	 	$idtestproject = $_REQUEST['idtestproject'];
		$id_employee = $_REQUEST['id_employee'];
		$id = $_REQUEST['idproject'];
		$indexcomment = $_REQUEST['indexcomment'];
		$newlang = $_REQUEST['newlang'];
		
		if ($_REQUEST['newlang'] == "EN") {
			include "../../value/value_en.php";
		} else if($_REQUEST['newlang'] == "VN") {
			include "../../value/value_vn.php";
		}
		else {
			include "../../value/value_kr.php";
		}
		
		$queryListErrorByIDPr = mysql_query("SELECT tp.IDTest, tp.IDProject, tp.IDEmployee, tp.Title, tp.TextTest, tp.Time, tp.`Status`,e.FullName,tp.`Delete`,tp.IDTestTemp,
				tp.IdPriorityColor,pp.IDView,pp.NameProject,pc.backgroundColor,pc.backgroundConfirm
			   FROM pr_testproject tp, employee e,pr_project pp,priority_color pc WHERE pp.IDProject = tp.IDProject AND tp.IDTest = '$idtestproject' AND tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			    AND pc.id = tp.IdPriorityColor ORDER BY IDTest DESC;");
$listattach = mysql_query('select id, testprojectid, filepath, filereal, filename, filetype, filesize, createdate
		 from pre_attach where testprojectid='.$idtestproject);
		
?>
<?php while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				$idemplTestpro = $row['IDEmployee'];
				$prdelete = $row['Delete'];
				$titletestpro = $row['Title'];
				$contenttestpro = $row['TextTest'];
				$fullnames = $row['FullName'];
				$time = $row['Time'];
				$idtesppr_temp = $row['IDTestTemp'];
				$idviewpro = $row['IDView'];
				$nampro = $row['NameProject'];
				
				$temp_mo = explode("-", $idtesppr_temp);
				$temp_mo_last = $temp_mo[0];
				$m="";
				if ($temp_mo_last==''){
					$m ="";
				}
				else if ($temp_mo_last==$nampro){
					$m = $idviewpro."-".$temp_mo[1];
				}else{
					$m = $idviewpro."-".$idtesppr_temp;
				}
				$titletestpro = $row['Title'];
				if (strpos($titletestpro,"-%$#@!-#")) {
					$titletestpro =  substr($titletestpro,0,strpos($titletestpro,"-%$#@!-#"));
				}
				$titletestpro = strip_tags($titletestpro);
				//tag html tranh be giao dien
				$titletestpro = eregi_replace(chr(13),"<br>",$titletestpro);
				$color = substr($row['Title'],-6); 
				$idtesppr_temp = $row['IDTestTemp'];  
				$bgcolor = $row['backgroundColor'];
				$IdPriorityColor = $row['IdPriorityColor'];
				$errorstatus = $row['Status'];
				$namestatus = "";
				if ($errorstatus == 0){
					$namestatus = $l_no_fix;
				}else if ($errorstatus == 1){
					$namestatus = $l_fix_complete;
				}else if ($errorstatus == 2){
					$bgcolor = $row['backgroundConfirm'];
					$namestatus = $l_confirm_excel;
				}
				?>
			<td class="rf-dt-c" 
						style="width: 5%; vertical-align: middle; text-align: center;min-width: 5%;"><?php echo $m?>
					</td>
					<td class="rf-dt-c"
						style="width: 9%; vertical-align: middle; text-align: center;min-width: 9%"><?php echo $namestatus?>
					</td>
					<td class="rf-dt-c" colspan="4"
						style="padding: 0; vertical-align: middle;">
						
						<div  style="background:white; border:1px solid #c4c0c9; padding:10px;margin:9px;" id="parentcommand">
						
							<div class="acomment" id="themcommand" style="background:white; border:1px solid #c4c0c9; padding:10px;display: none">
		                    	<span style="display: block; text-align: left"><?php echo $l_comment?> : </span>
		                    	<textarea style="width:100%; border:1px solid #c4c0c9" cols="5" rows="3" id="titlecomment" name="titlecomment"></textarea>
		                        <div style="text-align:right">
		                            <input class="buttonProject" type="button" style="margin: 5px 0;" value="OK" onclick="add_comment('<?=$idtestproject?>','<?=$id_employee?>',this);"/>
		                            <input class="buttonProject aclose" type="button" style="margin: 5px 0;" value="Cancel" id="cancelthemcommand" onclick="closethemcommand(this)"/>
		                        </div>
	                   		</div> 
							<div class="odd1" style=" padding-left:0px; border:1px solid #ddd; font-size: 13px;" id="ajaxLstComment">
								<div  style="background: <?php echo "#".$bgcolor;?>; padding:10px;  font-weight:bold;">
								<?php echo  $titletestpro ;?>
								</div>
								<div style="background:#ffffff;  padding:10px; "><?php echo $contenttestpro?></div>
								<div style="padding:0 8px">
								
								<?php 
								$temindex = 0;
								while ($rowattach = mysql_fetch_array($listattach)) {?>
									<div style="padding:1px">
										<img src="images/dinhkem.png"/>
										<a
											href="admin/attach/downloadattach.php?filepath=<?=$rowattach['filereal']?>&filename=<?=$rowattach['filename']?>&filetype=<?=$rowattach['filetype']?>">
											<?=$rowattach['filename']."(".$rowattach['filetype'].") ".$rowattach['filesize']?></a>
									</div>
								<?php $temindex+=1;}
								?>
								</div>
								<!-- div style="border-bottom: 1px dotted gray; padding-bottom: 5px;margin-bottom: 5px;"></div -->
							</div>
							
	                        <div style="background:#f7f7f7; width:100%"> 
	                            <div style=" padding:10px; font-size:11px; color:#000; float:left; width:60%"><?php echo $fullnames."(".$time.")"?></div>
	                            <div style="float:right;">
	                            	<?php 
									if ($errorstatus == -1){
									?>
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_fix_complete?>" id="showcommand1" onclick="errorfixed('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');"/>
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_confirm_excel?>" id="showcommand1" onclick="errorconfirm('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');" />
										|
									<?php 
									}elseif ($errorstatus == 0){
									?>
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_fix_complete?>" id="showcommand1" onclick="errorfixed('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');"/>
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_confirm_excel?>" id="showcommand1" onclick="errorconfirm('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');" />
										|
									<?php 
									}elseif ($errorstatus == 1){
									?>
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_confirm_excel?>" id="showcommand1" onclick="errorconfirm('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');" />
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_no_fix?>" id="showcommand1" onclick="errorunconfirm('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');" />
										|									
									<?php 
									}elseif ($errorstatus == 2){
									?>
										<input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_reopen?>" id="showcommand1" onclick="errorreopen('<?=$id?>','<?=$idtestproject?>','<?=$id_employee?>','<?=$page?>');"/>
										|
									<?php 
									}
									?>
	                                <input class="buttonProject hcomment" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_comment?>" id="showcommand1" onclick="showthemcommand(this)"/>
	                                <input class="buttonProject " type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_edit?>" 
	                                	onclick="edittile_testproject('<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$IdPriorityColor?>','<?=$bgcolor?>')" />
	                                <input class="buttonProject hclose" type="button" style="margin: 5px 0;min-width: 70px" value="<?php echo $l_close?>" onclick="onclickError('<?=$id?>','<?=$id_employee?>','<?=$page?>')"/>
	                           
	                            
	                             </div>
	                            <div class="clear"></div> 
	                        </div>
	                        
	                       
							<?php $querycomment = mysql_query("select c.IDComment,c.IDTestProject,c.IDEmployee,c.Comment,c.DateComment,
								 e.IDEmployee,e.FullName,c.IDTestProject from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = '$idtestproject' ORDER BY  c.DateComment ASC;")?>
	                       
	                       
	                        <div style="background:white; padding:5px; border:1px solid #ddd; font-size: 13px;"> 
	                        	<div style="background:white; padding:5px; border:1px solid #ddd;" id="ajaxcomment"> 
	                        <?php 
	                        if(count($querycomment)>0){
	                        	?>
	                  <table style="width: 100%;">
	                        <?php  
		                        $vitri=0;
		                        while ($rowcoment = mysql_fetch_array($querycomment)){
		                        	$vitri++;
		                        		$idcomment = $rowcoment['IDComment'];
		                        		$idemployeecomment = $rowcoment['IDEmployee'];
		                        		$stringcolor = $rowcoment['Comment'];
										if (strpos($stringcolor,"-%$#@!-#")) {
											$stringcolor =  substr($stringcolor,0,strpos($stringcolor,"-%$#@!-#"));
										}
										$stringcolor = strip_tags($stringcolor);
				
										?>
									
							<tr id="mo" style="background: <?php if($vitri%2==0) 
															echo '#f2f9ff'; 
													else echo '#ffffff';?>; font-size: 13px;">
								<td class="rf-dt-c" style="padding: 0; vertical-align: middle; width: auto;">
	                        
		                        	<span style=" color:#b023ab; font-size: 13px;"><font color="#424242"><?php echo  " + ".$stringcolor ?> </font>
									</span>
	                            	<i style="color:#424242; display:block; text-align:right; padding-top:5px;padding-right:15px; font-size: 13px;"><?php echo $rowcoment['FullName']." (".$rowcoment['DateComment'].")"?></i>
	                           </td>
	                           <td class="rf-dt-c" style="width: 25px; vertical-align: middle; text-align: center;min-width: 80px">
		                           <span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" style="color:#236DA4" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ delete_comment('<?=$idcomment?>','<?=$idtestproject?>','<?=$id_employee?>',this);return true}else{return false}">[ <?php echo $l_delete?> ]</span>
							   </td>
	                           
						</tr>
	                   <?php }?>
	               </table>
	               <?php }?>
	                       
	                     </div>
	                        </div>
	                        
						</div>
						
						</td>
						<?php }?>
					<?mysql_close($connection);?>